package com.qfjy.config.example2;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class WeatherFanoutConfig {
    /**
     * 1、定义交换机（Fanout)
     * 2、分别定义队列（京东、淘宝....)
     * 3、交换机和队列进行绑定
     */

    @Bean
    public FanoutExchange fanoutExchange(){
        return new FanoutExchange("weatherFanoutExchange");
    }

    /**
     * 2、分别定义队列（京东、淘宝....)
     */
    @Bean
    public Queue jdFanoutQueue(){
        return new Queue("jdWeatherFanoutQueue");
    }

    @Bean
    public Queue taobaoFanoutQueue(){
        return new Queue("taobaoWeatherFanoutQueue");
    }
    /**
     * 3、交换机和队列进行绑定
     *
     * 京东队列和交换机绑定
     */
    @Bean
    public Binding bindFanoutJdQueue(Queue jdFanoutQueue,FanoutExchange fanoutExchange){
        return BindingBuilder.bind(jdFanoutQueue).to(fanoutExchange);
    }
    @Bean
    public Binding bindFanoutTaobaoQueue(){
        return BindingBuilder.bind(taobaoFanoutQueue()).to(fanoutExchange());
    }
}
